package router

import (
	"log"
	_ "tosServer/internal/pkg/config"
	_ "tosServer/internal/pkg/db"

	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

type Route struct {
	httpRouter *gin.Engine
}

func (r *Route) Run() {

	//defer func() {
	//	if err := recover(); err != nil {
	//		slog.Error("触发recover：", err)
	//	}
	//}()

	if viper.Get("debug").(string) == "false" {
		gin.SetMode(gin.ReleaseMode)
	} else {
		gin.SetMode(gin.DebugMode)
	}

	r.httpRouter = gin.Default()

	r.docs()
	r.api()
	r.dav()

	err := r.httpRouter.Run(":" + viper.Get("port").(string))
	if err != nil {
		log.Fatalln(err)
		return
	}
}
